var request = require('../../utils/request.js')
var app = getApp();
Page({
  data: {
    pocketlist:'',
    charge_cardlist:"",
    discountslist: [],
  },
  onLoad: function () {
    // my.getUserInfo({
    //   success: function (res) {
    //     that.setData({
    //       user: { 'name': res.userInfo.nickName, 'avatar': res.userInfo.avatarUrl }
    //     })
    //   }
    // })
  },
  // 钱包明细
  moneyDetail:function(){
    my.navigateTo({
      url: '/pages/myWallet/detail'
    })
  },
  // 月卡
  renew: function () {
    my.navigateTo({
      url: '/pages/myWallet/renew'
    })
  },
  // 充值
  recharge: function () {
    my.navigateTo({
      url: '/pages/myWallet/recharge'
    })
  },
  // 权益
  monthlyCard: function () {
    my.navigateTo({
      url: '/pages/myWallet/interest'
    })
  },
  onShow: function () {
    my.getNetworkType({
      success: (res) => {
        if(!res.networkAvailable||res.networkType=='UNKNOWN'){
          my.showToast({
            content: '网络状态不佳，请检查网络',
            type:'fail',
            duration: 2000
          })
        }
      }
    })
    this.getuserinfo();
  },
  //获取页面数据
  getuserinfo() {
    let success = (res) => {
      if (res.charge_card){//月卡
        res.charge_card.remain_time = (parseInt(res.charge_card.remain_time) / 3600).toFixed(1)
        res.charge_card.expire = res.charge_card.expireAt.substring(0, 10)
        this.setData({
          charge_cardlist: res.charge_card,
        })
      }
      if (res.pocket){//钱包
        this.setData({
          pocketlist: res.pocket,
        })
      }
    }
    request.getdata("/users/user/show", {}, success, this);
  },
})